﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GtsServer.Model;
using GtsServer.Manage.Controller;
using GtsServer.Common;

namespace GtsServer.Manage.IISPage.Ajax {
    /// <summary>
    /// InitialSettingAjax 的摘要说明
    /// </summary>
    public class InitialSettingAjax : IHttpHandler {

        InitialSettingController Controller = new InitialSettingController();
        public void ProcessRequest(HttpContext context) {
            string type = string.Empty;
            if(context.Request["action"] != null) {
                type = context.Request["action"];

                switch(type) {
                    case "GetList":
                        GetList(context);
                        break;
                    case "Add":
                        Add(context);
                        break;
                    case "Update":
                        Update(context);
                        break;
                    case "Delete":
                        Delete(context);
                        break;
                    default:
                        break;
                }
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <param name="context"></param>
        private void GetList(HttpContext context) {
            List<InitialSetting> list = Controller.GetList();
            string json = JsonHelper.ListToJson<InitialSetting>(list);
            context.Response.Write(json);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="context"></param>
        private void Update(HttpContext context) {
            int id = Convert.ToInt32(context.Request["id"]);
            int prizeId = Convert.ToInt32(context.Request["PrizeId"]);
            int initialSettingcount = Convert.ToInt32(context.Request["InitialSettingcount"]);
            InitialSetting model = new InitialSetting() {
                Id = id,
                PrizeId = prizeId,
                InitialSettingcount = initialSettingcount,
            };
            context.Response.Write(Controller.Update(model));
        }
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="context"></param>
        private void Add(HttpContext context) {
            int prizeId = Convert.ToInt32(context.Request["PrizeId"]);
            int initialSettingcount = Convert.ToInt32(context.Request["InitialSettingcount"]);
            InitialSetting model = new InitialSetting() {
                PrizeId = prizeId,
                InitialSettingcount = initialSettingcount,
            };
            int id = Controller.Add(model);
            context.Response.Write(id);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="context"></param>
        private void Delete(HttpContext context) {
            int id = Int32.Parse(context.Request["id"]);
            context.Response.Write(Controller.Delete(id));
        }
        public bool IsReusable {
            get {
                return false;
            }
        }
    }
}